package com.xiaoyu.client.ui.activity.nearby;

import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.xiaoyu.client.R;
import com.xiaoyu.client.ui.activity.main.mine.set_favorable.AvailableFragment;
import com.xiaoyu.commonlib.ui.base.BaseActivityWithTitle;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author jx
 * @date 创建时间 2018/11/14
 * @Description 我的推荐
 */
public class MyRecommendActivity extends BaseActivityWithTitle {

    private View mView;
    private ImageView mRightImg;
    @BindView(R.id.wait_for_review)
    TextView mWaitReview;//等待审核
    @BindView(R.id.already_passed)
    TextView mAlreadyPass;//已经通过
    @BindView(R.id.has_been_rejected)
    TextView mHasRejected;//已驳回
    private List<Fragment> mFragments = new ArrayList<Fragment>();


    @Override
    protected void loadContentView(ViewGroup parent) {
        setTitleText("我的推荐");
        mView = LayoutInflater.from(this).inflate(R.layout.activity_my_recommend, parent, true);
        ButterKnife.bind(this);
        addRightImg();
        initView();
    }

    //添加右侧图片
    private void addRightImg() {
        mRightImg = new ImageView(this);
        mRightImg.setImageResource(R.mipmap.icon_share);
        mRightImg.setOnClickListener(this);
        addRightView(mRightImg, 0);
    }

    private void initView() {
        mWaitReview.setOnClickListener(this);
        mAlreadyPass.setOnClickListener(this);
        mHasRejected.setOnClickListener(this);
        PrepareFragment();
    }

    //准备fragment
    private void PrepareFragment() {
        mFragments.clear();
        mFragments.add(new MyRecommendationFragment(1));
        mFragments.add(new MyRecommendationFragment(2));
        mFragments.add(new MyRecommendationFragment(0));
        showFragment(0);
    }

    private void showFragment(int i) {
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.replace(R.id.activity_favorable_framelayout, mFragments.get(i));
        transaction.commit();
        switch (i) {
            case 0:
                mWaitReview.setTextColor(Color.parseColor("#ffffff"));
                mWaitReview.setBackgroundColor(Color.parseColor("#2796f0"));

                mAlreadyPass.setBackgroundColor(Color.parseColor("#DCDCDC"));
                mAlreadyPass.setTextColor(Color.parseColor("#333333"));

                mHasRejected.setBackgroundColor(Color.parseColor("#DCDCDC"));
                mHasRejected.setTextColor(Color.parseColor("#333333"));

                break;
            case 1:
                mWaitReview.setTextColor(Color.parseColor("#333333"));
                mWaitReview.setBackgroundColor(Color.parseColor("#DCDCDC"));

                mAlreadyPass.setTextColor(Color.parseColor("#ffffff"));
                mAlreadyPass.setBackgroundColor(Color.parseColor("#2796f0"));

                mHasRejected.setTextColor(Color.parseColor("#333333"));
                mHasRejected.setBackgroundColor(Color.parseColor("#DCDCDC"));
                break;
            case 2:
                mWaitReview.setTextColor(Color.parseColor("#333333"));
                mWaitReview.setBackgroundColor(Color.parseColor("#DCDCDC"));

                mAlreadyPass.setBackgroundColor(Color.parseColor("#DCDCDC"));
                mAlreadyPass.setTextColor(Color.parseColor("#333333"));

                mHasRejected.setBackgroundColor(Color.parseColor("#2796f0"));
                mHasRejected.setTextColor(Color.parseColor("#ffffff"));

        }
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if (v == mWaitReview) {//等待审核
            showFragment(0);
        }
        if (v == mAlreadyPass) {//已经通过
            showFragment(1);
        }
        if (v == mHasRejected) {//已驳回
            showFragment(2);
        }
    }
}